/**
    list.h - Header file for list.c.
    Copyright (C) 2009  Abram Magner

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIST_H
  #define LIST_H

  #define list_get_iter(li) ((li)->head)
  #define list_iter_advance(it) (it = (it)->next)
  #define list_iter_rewind(it) (it = (it)->prev)
  #define list_iter_hasmore(it) ((it) != NULL)

  typedef struct list_node
  {
    struct list_node *prev, *next;
    void *data;
  } list_node;

  typedef struct list
  {
    list_node *head;
    list_node *tail;
    size_t length;
  } list;

  list *new_list (void);
  void free_list (list *);
  void free_list_and_data (list *);

  int list_insert (list *, int, void *);
  void *list_get (list *, int);
  list_node *list_get_node (list *, int);
  void list_iterate (list *, void (*)(void *));
  void *list_remove (list *, int);
#endif
